<template>
    <div>
        <van-form @submit="onSubmit">
            <h1 style="margin-left: 150px;">注册豆瓣</h1>
            <p style="margin-left:5px;">新手机号将自动注册，请详读<span style="color: green;">豆瓣使用协议、豆瓣个人信</span></p>
            <p style="margin-left: 150px;color: green;margin-top: -20px;">息保护政策</p>
            <van-cell-group inset>
                <van-field v-model="username" name="username" placeholder="手机号/邮箱"
                    :rules="[{ required: true, message: '请填写用户名' }]" />
                <van-field v-model="password" type="password" name="password" placeholder="密码"
                    :rules="[{ required: true, message: '请填写密码' }]" />
            </van-cell-group>
            <div style="margin: 16px;">
                <van-button style="background-color:yellowgreen;border: none;" block type="primary"
                    native-type="submit">
                    注册
                </van-button>
            </div>

        </van-form>

        <img src="../img/注册_02.jpg" alt="" style="width: 100%;margin-left: -2px;">

    </div>
</template>

<script setup>
import { ref } from 'vue';
import { registerApi } from '@/api/api';
import { useRouter } from 'vue-router';
const router = useRouter()
import { showSuccessToast, showFailToast } from 'vant';
const username = ref('');
const password = ref('');
const onSubmit = (values) => {
    console.log('submit', values);
    registerApi(username.value, password.value).then(res => {
        console.log(res);
        if (res.data.code == 0) {
            showSuccessToast('注册成功');
            router.push('/login')
        } else {
            showFailToast('注册失败');
        }

    })
};

</script>

<style lang="scss" scoped></style>